var fs=require('fs'),path=require('path');

module.exports= function (dir) {
    var cnt=0;
    return function (req,res,next) {
        var _path=path.join(
            dir,
            Date.now()+'-'+(cnt++)+'.txt'//形成字符串
        );

        var ws=fs.createWriteStream(_path);
        ws.write('Time:'+new Date().toString()+'\n\n');
        ws.write('Method:'+req.method+'\n\n');
        ws.write('Url:'+req.url+'\n\n');
        ws.write('Headers:'+JSON.stringify(req.headers,null,2)+'\n\n');
        next();
    }
};